package main

import (
	"fmt"
	"os"

	"gddgame.cc/galaxy"
	"gddgame.cc/galaxy/binocle/galaxy_provide"
	"gddgame.cc/galaxy/common/bootstrap"
	"gddgame.cc/galaxy/project/star/star"
)

func main() {
	galaxy.SetInfo("Star Game", "守护星球Online游戏服务器", star.Version)
	if err := galaxy.Init(func() error {
		return galaxy.PreStart(bootstrap.DefaultBoot.ParseConfig)
	}, func() error {
		return galaxy.Start(registerBinocle, register)
	}); err != nil {
		fmt.Fprint(os.Stderr, err)
		fmt.Print("\n")
		os.Exit(1)
	}
}

func register() error {
	component := &star.Component{Config: &star.Config{}}

	return galaxy.RegisterServer(galaxy.ServerProvider{
		Name:   "star",
		Config: component.Config,
		Inject: component,
		OnCreate: func() error {
			component.Component(component)
			return nil
		},
		OnStop: func() error {
			return component.Nebula.Close()
		},
	})
}
func registerBinocle() error {
	return galaxy.RegisterServer(galaxy_provide.AgentProvide())
}
